command mit_prep_msh_rtf()
{
	point = 0;	string_replace( "~", "", 0 );// the tildes were only to keep the bookmarks separated.
	point = 0;	string_replace( "{\\\*\\bkmk", "\n{\\\*\\bkmk", 0 );// ensure all bookmarks start a new line.
	point = 0;	string_replace( "{\header ", "\n{\header ", 0 );// ensure all headers start a new line.
	point = 0;	string_replace( "{\footer ", "\n{\footer ", 0 );// ensure all footers start a new line.
	point = 0;	string_replace( "\par }}", "\par }}\n", 0 );// header/footer endings
/*	point = 0;	string_replace( "\\cell([^x])", "\n\\cell\n#1", REGEX );//ensure all cell instructions are alone on a line */
	point = 0;	string_replace( " ?\\cell![^x] ?", "\n\\cell\n", REGEX );//ensure all cell instructions are alone on a line  -- use lookahead so we don't have to restore the extra characters we searched for.
	point = 0;	mit_isolateBkmkOnAnyLine();
	point = 0;
	while (re_search(1,"bkmk[^}]+$")){
		delete(point,point+1);//remove the newline
	}
	point = 0;	string_replace( "^ +\}", "}", REGEX );// get rid of white space
	point = 0;	string_replace( "\n\n", "\n", 0 );// get rid of white space I created.
	point = 0;	string_replace( "\n\n", "\n", 0 );// get rid of white space I created.
	point = 0;	string_replace( "\n\n", "\n", 0 );// get rid of white space I created.
	point = 0;	string_replace( "\n\n", "\n", 0 );// get rid of white space I created.
	point = 0;	string_replace( "\n \n", "\n", 0 );// get rid of white space I created.
	//Escape with % for epsilon, escape \ with \ because its in a string.
	point = 0;	string_replace( "%{\\%*\\bkmkstart MG_(.+)%}", "#0<!$MG_#1>", REGEX );

	point = 0;	string_replace( "%{\\%*\\bkmkstart MGR_(.+)%}", "#0<!$MGIF_#1><!$MGREPEAT>", REGEX );
	point = 0;	string_replace( "%{\\%*\\bkmkend MGR_(.+)%}", "<!$MGENDREPEAT><!$MGENDIF>#0", REGEX );

	point = 0;	string_replace( "%{\\%*\\bkmkstart MGIF_(.+)%}", "#0<!$MGIF_#1>", REGEX );
	point = 0;	string_replace( "%{\\%*\\bkmkend MGIF_(.+)%}", "<!$MGENDIF>#0", REGEX );

}
command mit_isolateBkmkOnAnyLine()
{
	while( search( 1, "\\\*\\bkmkstart" )){
		search( 1, "}" );
		stuff("~\n");
	}
	point = 0;
	while( search( 1, "\\\*\\bkmkend" )){
		search( 1, "}" );
		stuff("~\n");
	}
}
